package com.syni.mdd.yhd.common.all.controller.api.video;

import com.syni.mdd.sjb.common.component.utils.common.utils.RpcResponseVo;
import com.syni.mdd.yhd.common.all.constants.Constants;
import com.syni.mdd.yhd.common.all.entity.BmsVideo;
import com.syni.mdd.yhd.common.all.enums.video.VideoEnums;
import com.syni.mdd.yhd.common.all.service.BmsVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.Optional;

/**
 * @className VideoRestApi
 * @description TOO
 * @Author cfx
 * @DATE 2020/3/9 14:07
 * @VERSION 1.0
 **/
@RestController
@RequestMapping("/apiVideo")
public class VideoRestApi {
    @Autowired
    BmsVideoService bmsVideoService;

    @GetMapping("/getVideoById")
    public RpcResponseVo getVideoById(Integer videoId){

        Optional<BmsVideo> bmsVideo = bmsVideoService.getBaseDao().findById(videoId);
        if(bmsVideo.isPresent()){
            //直接扔实体对象还是包装自己vo决定
            return RpcResponseVo.success(bmsVideo);
            //return RpcResponseVo.success()
        }
        //也可以直接返回状态码和提示语
        //return RpcResponseVo.result("01","视频不存在");
        //返回枚举
        return RpcResponseVo.result(VideoEnums.VIDEO_NO_EXIST);
    }

    @PostMapping("/insertMtMachineVideo")
    public RpcResponseVo insertMtMachineVideo(@RequestBody BmsVideo bmsVideo){
        bmsVideo.setIsOff(Constants.COMMON_FLAG_TRUE_INT);
        bmsVideo.setIsDelete(Constants.COMMON_FLAG_TRUE_INT);
        bmsVideo.setNewTime(new Date());
        bmsVideo.setFromOrigin(Constants.RELEASE_BY_MT_APP);
        bmsVideo = bmsVideoService.getBaseDao().save(bmsVideo);
        if(bmsVideo.getId() != null){
            return RpcResponseVo.success(bmsVideo);
        }
        return RpcResponseVo.result(VideoEnums.VIDEO_INSERT_FAIL);
    }
}
